<template>
  <a-modal :title="title" :visible="visible" class="pub-middle-dialog" @ok="handleOk" @cancel="visible = false">
    <a-table :loading="loading" :pagination="false" :columns="columns" :data-source="tableData" row-key="id">
      <span slot="num" slot-scope="text, record, index">{{ index + 1 }}</span>
      <div slot="operation" slot-scope="text, record, index" class="pub-table-list-action">
        <span @click="handleEdit(record, 3)">查看</span>
      </div>
    </a-table>
  </a-modal>
</template>
<script>
import { historyList } from '@/api/material/materialMasterPlan/materialPlan'

export default {
  name: 'a' + Date.now(),
  props: {
    id: {
      type: String
    },
    title: {
      type: String,
      default: '历史记录选择'
    },
    btnCb: {
      type: Function
    }
  },
  data: function () {
    return {
      pageNo: 1,
      pageSize: 10,
      totalSize: 0,
      visible: false,
      loading: false,
      tableData: [],
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'num' }
        },
        {
          title: '变更人',
          dataIndex: 'changeUser'
        },
        {
          title: '变更时间',
          dataIndex: 'modifiedTime'
        },
        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operation' }
        }
      ]
    }
  },
  methods: {
    open: function (params = null) {
      this.visible = true
      this.list(params)
    },
    handleOk: function () {
      this.visible = false
    },
    async list(params) {
      this.loading = true
      let res = await historyList({ id: params ? params : this.id })
      this.loading = false
      this.tableData = res.data
      this.totalSize = res.totalElements
    },
    handleEdit(record, state) {
      if (this.btnCb) {
        this.btnCb(record, state)
      } else {
        this.$router.push({
          path: '/material/materialMasterPlanAdd',
          query: {
            // row: record,
            id: record && record.id || '',
            targetPage: 'history',
            state: state
          }
        })
      }
    }
  }
}
</script>